package com.military.service.impl;

import com.military.mapper.MilitaryStandardMapper;
import com.military.pojo.descriptionOption;
import com.military.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MilitaryStandardMapper  militaryStandardMapper;

    /**
     * 统计军标模型数据
     * @return
     */
    @Override
    public descriptionOption getMilitaryData() {
        //1.调用mapper接口, 获取统计数据
        List<Map<String, Object>> list = militaryStandardMapper.countMilitaryData();//map: pos = 坦克模型,num= 1

        //2. 组装结果,并返回
        List<Object> descriptionList = list.stream().map(dataMap -> dataMap.get("pos")).toList();//遍历获取到的元素封装到新的list集合
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();

        return new descriptionOption(descriptionList,dataList);
    }
}
